// Copyright. All rights reserved.

/*
Package sentry ....
*/
package sentry

import (
	"github.com/getsentry/raven-go"
)

// SetDSN set dsn for sentry.
func SetDSN(dsn string) error {
	if SentryUsing {
		return raven.SetDSN(dsn)
	}
	return nil
}

// Msg CaptureMessage of sentry封装.
func Msg(msg, level string, args ...interface{}) {
	if SentryUsing {
		var nargs []raven.Interface
		for _, arg := range args {
			if v, ok := arg.(raven.Interface); ok {
				nargs = append(nargs, v)
			}
		}
		pkt := raven.NewPacket(msg, nargs...)
		v := raven.Severity(level)
		switch v {
		case raven.DEBUG:
			pkt.Level = raven.DEBUG
		case raven.INFO:
			pkt.Level = raven.INFO
		case raven.WARNING:
			pkt.Level = raven.WARNING
		case raven.ERROR:
			pkt.Level = raven.ERROR
		case raven.FATAL:
			pkt.Level = raven.FATAL
		default:
			pkt.Level = raven.ERROR
		}
		raven.Capture(pkt, nil)
		//raven.CaptureMessage(msg, map[string]string{"level": level}, nargs...)
	}
}

// Info sentry info message.
func Info(msg string, args ...interface{}) {
	Msg(msg, "info", args...)
}

// Warn sentry warn message.
func Warn(msg string, args ...interface{}) {
	Msg(msg, "warning", args...)
}

// Error sentry error message.
func Error(msg string, args ...interface{}) {
	Msg(msg, "error", args...)
}

// Faltal sentry error message.
func Faltal(msg string, args ...interface{}) {
	Msg(msg, "fatal", args...)
}
